﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.LoadData();                
            }
        }

        private void LoadData()
        {

            this.ASPxGridView1.DataSource = getDataTable();
            this.ASPxGridView1.DataBind();

        }

        private DataTable getDataTable()
        {

            DataTable dt = new DataTable();
            DataColumn column;
            DataRow dr;

            column = new DataColumn();            
            column.ColumnName = "Id";
            column.DataType = Type.GetType("System.String");
            column.AllowDBNull = false;
            column.Unique = true;
            dt.Columns.Add(column);

            column = new DataColumn();
            column.ColumnName = "Name";
            column.DataType = Type.GetType("System.String");
            column.AllowDBNull = true;
            column.Unique = false;
            dt.Columns.Add(column);

            column = new DataColumn();
            column.ColumnName = "Sno";
            column.DataType = Type.GetType("System.String");
            column.AllowDBNull = true;
            column.Unique = false;
            dt.Columns.Add(column);

            column = new DataColumn();
            column.ColumnName = "School";
            column.DataType = Type.GetType("System.String");
            column.AllowDBNull = true;
            column.Unique = false;
            dt.Columns.Add(column);

            for (int i = 4; i >= 0; i--)
            {
                dr = dt.NewRow();
                dr["Id"] = i;
                dr["Name"] = "Name" + i;
                dr["Sno"] = "1530" + i;
                dr["School"] = "School No" + i;
                dt.Rows.Add(dr);
            }

            return dt;

        }

        protected void ASPxGridView1_AfterPerformCallback(object sender, DevExpress.Web.ASPxGridViewAfterPerformCallbackEventArgs e)
        {

        }

        protected void ASPxGridView1_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridViewTableRowEventArgs e)
        {
            if (this.Enable_RowOverOut_ColorChange) 
            {
                if (e.RowType == DevExpress.Web.GridViewRowType.Header) { return; } //表头不设置

                #region  "  setting Row.Atrributes "

                //string atrr = "background-color:#123456;"; //背景
                //atrr += "cursor:pointer;";//指针
                //e.Row.Attributes["style"] = atrr;

                e.Row.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#D3D3D3';  this.style.cursor='pointer';";
                e.Row.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#FFFFFF';  this.style.cursor='default';";

                #endregion
            }
            
        }

        public bool Enable_RowOverOut_ColorChange { get; set; }
    }
}